#include "trade.h"
#include <QDebug>

Trade::Trade(QObject *parent) :
    QObject(parent)
{
}

Trade::Trade(const QStringList &valSymbols, QObject *parent)
{
    /*init value map*/
    for(int i=0;i<valSymbols.count();i++)
        values.insert(valSymbols.at(i),new QStandardItem());
}

Trade::Trade(const QStringList &valSymbols, const QStringList &values, QObject *parent)
{
    /*init value map*/
    for(int i=0;i<valSymbols.count();i++)
    {
        QStandardItem* tmp=new QStandardItem();
        tmp->setData(values.at(i));
        tmp->setText(values.at(i));
        this->values.insert(valSymbols.at(i),tmp);
    }
}

void Trade::addValue(const QString &valSymbol, QVariant value)
{
    QStandardItem* tmp=new QStandardItem();
    tmp->setData(value);
    tmp->setText(value.toString());
    values.insert(valSymbol,tmp);
}

void Trade::addValue(const QMap<QString, QVariant> &values)
{
    QMap<QString,QVariant>::const_iterator iter=values.constBegin();
    qDebug()<<"Trade::addValue(): "<<"Adding map values: "<<values;
    for(iter;iter!=values.constEnd();++iter)
    {
        QStandardItem* tmp=new QStandardItem();
        tmp->setData(iter.value());
        tmp->setText(iter.value().toString());
        this->values.insert(iter.key(),tmp);
    }
    qDebug()<<"Trade::addValue(): "<<"Value map: "<<this->values;
}

QString Trade::getValue(const QString &valSymbol)const
{
    return values.value(valSymbol)->data().toString();
}

QStringList Trade::getValues() const
{
    QStringList ret;
    QMap<QString,QStandardItem*>::const_iterator iter=values.constBegin();
    for(iter;iter!=values.constEnd();++iter)
    {
        ret<<iter.value()->data().toString();
    }
    return ret;
}

QMap<QString, QVariant> Trade::getValueMap() const
{
    QMap<QString,QVariant> ret;
    QMap<QString,QStandardItem*>::const_iterator iter=values.constBegin();
    for(iter;iter!=values.constEnd();++iter)
    {
        ret.insert(iter.key(),iter.value()->data());
    }
    return ret;
}

QList<QStandardItem *> Trade::getAllItems()
{
    return values.values();
}

QMap<QString, QStandardItem *> Trade::getItemMap()
{
    return values;
}

void Trade::setStockName(const QString &stockName)
{
    this->stockName=stockName;
}

QString Trade::getStockName() const
{
    return stockName;
}
